package cz.vargarob.spring;

import org.apache.commons.logging.Log;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import cz.vargarob.spring.service.TransferService;
import cz.vargarob.spring.test.InitializationTestBean;
import cz.vargarob.spring.test.PropertiesTestBean;
import cz.vargarob.spring.test.UtilNsTestBean;

public class Main {
	
	public static void  main(String [] args){
//		ApplicationContext context = new ClassPathXmlApplicationContext("spring-conf/myContext.xml");
//		ApplicationContext context = new FileSystemXmlApplicationContext("C:\\Workspaces\\SpringCertWorkspace\\SpringBasic\\src\\main\\resources\\spring-conf\\myContext.xml");
//		ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/main/resources/spring-conf/myContext.xml", "classpath:spring-conf/secondContext.xml");
		ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/main/resources/spring-conf/myContext.xml");
		Log myLog = context.getBean(Log.class);

		myLog.info("######### BASIC BEAN CALLING ##########");

		TransferService t = (TransferService) context.getBean("transferService");
		myLog.info(t.getName());

		myLog.info("######### BEAN WITH PLACEHOLDER PARAMS ##########");
		
		PropertiesTestBean propertiesTestBean = context.getBean(PropertiesTestBean.class);
		myLog.info(propertiesTestBean.getPlaceholderAtribue());
		myLog.info(propertiesTestBean.getSecondPlaceholderAtribue());

		myLog.info("######### BEAN SETUP(PROPERTY EDITORS) & HIERARCHY ##########");
		
		// FAIL: parent is abstract
		//InitializationTestBean initTestBeanParent = context.getBean("initializationTestBeanParent",InitializationTestBean.class);
		InitializationTestBean initTestBean = context.getBean("initializationTestBeanChild",InitializationTestBean.class);
		myLog.info("List size is " + initTestBean.getListOfStringVals().size());
		myLog.info("Boolean prop type is "+ (initTestBean.getBooleanProp() instanceof Boolean)+ " xxx " +initTestBean.getBooleanProp());
		myLog.info("Long prop type is "+ (initTestBean.getLongProp() instanceof Long)+ " xxx " +initTestBean.getLongProp());
		myLog.info("Integer prop type is "+ (initTestBean.getIntProp() instanceof Integer)+ " xxx " +initTestBean.getIntProp());
		myLog.info("String prop type is "+ (initTestBean.getStringProp() instanceof String) + " xxx " +initTestBean.getStringProp());
		myLog.info("Double prop type is "+ (initTestBean.getDoubleProp() instanceof Double) + " xxx " +initTestBean.getDoubleProp());
		myLog.info("Date prop type is "+ (initTestBean.getDateProp() instanceof java.util.Date) + " xxx " +initTestBean.getDateProp());
		myLog.info("Inner Bean value " +initTestBean.getInnerTestBean().getTestProp());
		myLog.info("Converted Bean value " +initTestBean.getPropertyEditedTestBean().getTestProp());
		
		myLog.info("######### UTIL NS ##########");

		UtilNsTestBean utilTestBean = context.getBean(cz.vargarob.spring.test.UtilNsTestBean.class);
		myLog.info("Constant value " + utilTestBean.getTestProperty());
		myLog.info("Size of LIST is " + utilTestBean.getListOfTestBeans().size());
		myLog.info("Size of MAP is " + utilTestBean.getMapOfTestBeans().size());
		myLog.info("Size of SET is " + utilTestBean.getSetOfTestBeans().size());
		
		myLog.info("######### JAVA-CONFIG STYLE CONFIG ##########");

		context.close();
		
	}

}
